﻿<!--
// (c) Copyright Microsoft Corporation.
// This source is subject to the Microsoft Public License (Ms-PL).
// Please see http://go.microsoft.com/fwlink/?LinkID=131993 for details.
// All other rights reserved.
-->

<UserControl x:Class="System.Windows.Controls.Samples.QueryNavigationSample"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:navigation="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Navigation">
    <StackPanel Background="White">
        <StackPanel>
            <ContentControl Content="Navigation" Style="{StaticResource Header}" />
            <TextBlock Style="{StaticResource Information}" Margin="4">
                Try changing the query below and clicking Navigate, then use the browser's back and forward buttons to change the page.
            </TextBlock>
            <ContentControl Content="Parameters" Style="{StaticResource Header}" />
            <StackPanel Orientation="Horizontal">
                <StackPanel Margin="4">
                    <TextBlock Text="X" />
                    <TextBox x:Name="x" Width="75" Text="xvalue" />
                </StackPanel>
                <StackPanel Margin="4">
                    <TextBlock Text="Y" />
                    <TextBox x:Name="y" Width="75" Text="yvalue" />
                </StackPanel>
                <StackPanel Margin="4">
                    <TextBlock Text="Z" />
                    <TextBox x:Name="z" Width="75" Text="zvalue" />
                </StackPanel>
            </StackPanel>
            <Button Content="Navigate" HorizontalAlignment="Left" Margin="4" Width="75" Height="23" Click="Button_Click" />
        </StackPanel>
        <StackPanel Orientation="Horizontal" Margin="4">
            <TextBlock Text="Current Url: " />
            <TextBlock Text="{Binding Source, ElementName=navFrame}" />
        </StackPanel>
        <ContentControl Content="Frame" Style="{StaticResource Header}" />
        <Grid Width="600" Height="400" HorizontalAlignment="Left">
            <Rectangle Stroke="Black" StrokeThickness="2" />
            <navigation:Frame x:Name="navFrame" Source="/Navigation/QueryPage.xaml" Margin="2" VerticalContentAlignment="Stretch" HorizontalContentAlignment="Stretch" UriMapper="{StaticResource UriMapper}" />
        </Grid>
        <src:SourceViewer xmlns:src="clr-namespace:System.Windows.Controls.Samples;assembly=System.Windows.Controls.Samples.Common" xmlns:sys="clr-namespace:System;assembly=mscorlib">
  <src:SourceFile Path="QueryNavigationSample.xaml">
    <src:SourceFile.Source>
      <sys:String>&lt;!--
// (c) Copyright Microsoft Corporation.
// This source is subject to the Microsoft Public License (Ms-PL).
// Please see http://go.microsoft.com/fwlink/?LinkID=131993 for details.
// All other rights reserved.
--&gt;

&lt;UserControl x:Class="System.Windows.Controls.Samples.QueryNavigationSample"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:navigation="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Navigation"&gt;
    &lt;StackPanel Background="White"&gt;
        &lt;StackPanel&gt;
            &lt;ContentControl Content="Navigation" Style="{StaticResource Header}" /&gt;
            &lt;TextBlock Style="{StaticResource Information}" Margin="4"&gt;
                Try changing the query below and clicking Navigate, then use the browser's back and forward buttons to change the page.
            &lt;/TextBlock&gt;
            &lt;ContentControl Content="Parameters" Style="{StaticResource Header}" /&gt;
            &lt;StackPanel Orientation="Horizontal"&gt;
                &lt;StackPanel Margin="4"&gt;
                    &lt;TextBlock Text="X" /&gt;
                    &lt;TextBox x:Name="x" Width="75" Text="xvalue" /&gt;
                &lt;/StackPanel&gt;
                &lt;StackPanel Margin="4"&gt;
                    &lt;TextBlock Text="Y" /&gt;
                    &lt;TextBox x:Name="y" Width="75" Text="yvalue" /&gt;
                &lt;/StackPanel&gt;
                &lt;StackPanel Margin="4"&gt;
                    &lt;TextBlock Text="Z" /&gt;
                    &lt;TextBox x:Name="z" Width="75" Text="zvalue" /&gt;
                &lt;/StackPanel&gt;
            &lt;/StackPanel&gt;
            &lt;Button Content="Navigate" HorizontalAlignment="Left" Margin="4" Width="75" Height="23" Click="Button_Click" /&gt;
        &lt;/StackPanel&gt;
        &lt;StackPanel Orientation="Horizontal" Margin="4"&gt;
            &lt;TextBlock Text="Current Url: " /&gt;
            &lt;TextBlock Text="{Binding Source, ElementName=navFrame}" /&gt;
        &lt;/StackPanel&gt;
        &lt;ContentControl Content="Frame" Style="{StaticResource Header}" /&gt;
        &lt;Grid Width="600" Height="400" HorizontalAlignment="Left"&gt;
            &lt;Rectangle Stroke="Black" StrokeThickness="2" /&gt;
            &lt;navigation:Frame x:Name="navFrame" Source="/Navigation/QueryPage.xaml" Margin="2" VerticalContentAlignment="Stretch" HorizontalContentAlignment="Stretch" UriMapper="{StaticResource UriMapper}" /&gt;
        &lt;/Grid&gt;
    &lt;/StackPanel&gt;
&lt;/UserControl&gt;
</sys:String>
    </src:SourceFile.Source>
  </src:SourceFile>
  <src:SourceFile Path="QueryNavigationSample.xaml.cs">
    <src:SourceFile.Source>
      <sys:String>// (c) Copyright Microsoft Corporation.
// This source is subject to the Microsoft Public License (Ms-PL).
// Please see http://go.microsoft.com/fwlink/?LinkID=131993 for details.
// All other rights reserved.

using System.ComponentModel;
using System.Globalization;

namespace System.Windows.Controls.Samples
{
    /// &lt;summary&gt;
    /// Sample page demonstrating navigation with query strings.
    /// &lt;/summary&gt;
    [Sample("(1)Using a Query String", DifficultyLevel.Intermediate)]
    [Category("Navigation")]
    public partial class QueryNavigationSample : UserControl
    {
        /// &lt;summary&gt;
        /// Initializes a QueryNavigationSample.
        /// &lt;/summary&gt;
        public QueryNavigationSample()
        {
            InitializeComponent();
        }

        /// &lt;summary&gt;
        /// Causes navigation when a button is clicked.
        /// &lt;/summary&gt;
        /// &lt;param name="sender"&gt;The clicked button.&lt;/param&gt;
        /// &lt;param name="e"&gt;Event arguments.&lt;/param&gt;
        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode", Justification = "Used by event defined in Xaml.")]
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            navFrame.Navigate(new Uri(string.Format(CultureInfo.CurrentCulture, "/Navigation/QueryPage.xaml?x={0}&amp;y={1}&amp;z={2}", Uri.EscapeDataString(x.Text), Uri.EscapeDataString(y.Text), Uri.EscapeDataString(z.Text)), UriKind.Relative));
        }
    }
}
</sys:String>
    </src:SourceFile.Source>
  </src:SourceFile>
  <src:SourceFile Path="QueryNavigationSample.xaml.vb">
    <src:SourceFile.Source>
      <sys:String>' (c) Copyright Microsoft Corporation.
' This source is subject to the Microsoft Public License (Ms-PL).
' Please see http://go.microsoft.com/fwlink/?LinkID=131993 for details.
' All other rights reserved.

Imports System.ComponentModel
Imports System.Globalization

''' &lt;summary&gt;
''' Sample page demonstrating navigation with mapped URIs.
''' &lt;/summary&gt;
&lt;Sample("(1)Using a Query String", DifficultyLevel.Intermediate)&gt; _
&lt;Category("Navigation")&gt; _
Public Class QueryNavigationSample
    Inherits UserControl

    ''' &lt;summary&gt;
    ''' Initializes a QueryNavigationSample.
    ''' &lt;/summary&gt;
    Public Sub New()
        InitializeComponent()
    End Sub

    ''' &lt;summary&gt;
    ''' Causes navigation when a page button is clicked.
    ''' &lt;/summary&gt;
    ''' &lt;param name="sender"&gt;The clicked button.&lt;/param&gt;
    ''' &lt;param name="e"&gt;Event arguments.&lt;/param&gt;
    &lt;System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode", Justification:="Used by event defined in Xaml.")&gt; _
    Private Sub Button_Click(ByVal sender As Object, ByVal e As RoutedEventArgs)
        navFrame.Navigate(New Uri(String.Format(CultureInfo.CurrentCulture, "/Navigation/QueryPage.xaml?x={0}&amp;y={1}&amp;z={2}", Uri.EscapeDataString(x.Text), Uri.EscapeDataString(y.Text), Uri.EscapeDataString(z.Text)), UriKind.Relative))
    End Sub
End Class
</sys:String>
    </src:SourceFile.Source>
  </src:SourceFile>
  <src:SourceFile Path="QueryPage.xaml">
    <src:SourceFile.Source>
      <sys:String>&lt;!--
// (c) Copyright Microsoft Corporation.
// This source is subject to the Microsoft Public License (Ms-PL).
// Please see http://go.microsoft.com/fwlink/?LinkID=131993 for details.
// All other rights reserved.
--&gt;
    
&lt;navigation:Page x:Class="System.Windows.Controls.Samples.QueryPage" 
           xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
           xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
           xmlns:navigation="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Navigation"
           Title="QueryPage Page"&gt;
    &lt;Grid Background="LightPink"&gt;
        &lt;StackPanel&gt;
            &lt;ContentControl Style="{StaticResource Header}" Content="Query string values" /&gt;
            &lt;Grid&gt;
                &lt;Grid.RowDefinitions&gt;
                    &lt;RowDefinition Height="Auto" /&gt;
                    &lt;RowDefinition Height="Auto" /&gt;
                    &lt;RowDefinition Height="Auto" /&gt;
                    &lt;RowDefinition /&gt;
                &lt;/Grid.RowDefinitions&gt;
                &lt;Grid.ColumnDefinitions&gt;
                    &lt;ColumnDefinition Width="Auto" /&gt;
                    &lt;ColumnDefinition /&gt;
                &lt;/Grid.ColumnDefinitions&gt;
                &lt;TextBlock Text="X =" Grid.Row="0" Margin="4" /&gt;
                &lt;TextBlock Text="Y =" Grid.Row="1" Margin="4" /&gt;
                &lt;TextBlock Text="Z =" Grid.Row="2" Margin="4" /&gt;
                &lt;TextBlock x:Name="x" Grid.Row="0" Grid.Column="1" Margin="4" /&gt;
                &lt;TextBlock x:Name="y" Grid.Row="1" Grid.Column="1" Margin="4" /&gt;
                &lt;TextBlock x:Name="z" Grid.Row="2" Grid.Column="1" Margin="4" /&gt;
            &lt;/Grid&gt;
        &lt;/StackPanel&gt;
    &lt;/Grid&gt;
&lt;/navigation:Page&gt;
</sys:String>
    </src:SourceFile.Source>
  </src:SourceFile>
  <src:SourceFile Path="QueryPage.xaml.cs">
    <src:SourceFile.Source>
      <sys:String>// (c) Copyright Microsoft Corporation.
// This source is subject to the Microsoft Public License (Ms-PL).
// Please see http://go.microsoft.com/fwlink/?LinkID=131993 for details.
// All other rights reserved.

using System.Windows.Navigation;

namespace System.Windows.Controls.Samples
{
    /// &lt;summary&gt;
    /// A Page that displays values assigned by query string.
    /// &lt;/summary&gt;
    public partial class QueryPage : Page
    {
        /// &lt;summary&gt;
        /// Initializes a QueryPage.
        /// &lt;/summary&gt;
        public QueryPage()
        {
            InitializeComponent();
        }

        /// &lt;summary&gt;
        /// Executes when the user navigates to this page.
        /// &lt;/summary&gt;
        /// &lt;param name="e"&gt;Event arguments.&lt;/param&gt;
        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            x.Text = GetArgument("x");
            y.Text = GetArgument("y");
            z.Text = GetArgument("z");
        }

        /// &lt;summary&gt;
        /// Gets a value passed in through the query if available.
        /// &lt;/summary&gt;
        /// &lt;param name="argName"&gt;The key to find.&lt;/param&gt;
        /// &lt;returns&gt;The value associated with the key if available, otherwise "{Not Specified}".&lt;/returns&gt;
        private string GetArgument(string argName)
        {
            if (NavigationContext.QueryString.ContainsKey(argName))
            {
                return NavigationContext.QueryString[argName];
            }
            return "{Not Specified}";
        }
    }
}
</sys:String>
    </src:SourceFile.Source>
  </src:SourceFile>
  <src:SourceFile Path="QueryPage.xaml.vb">
    <src:SourceFile.Source>
      <sys:String>' (c) Copyright Microsoft Corporation.
' This source is subject to the Microsoft Public License (Ms-PL).
' Please see http://go.microsoft.com/fwlink/?LinkID=131993 for details.
' All other rights reserved.

''' &lt;summary&gt;
''' A Page that displays values assigned by query string.
''' &lt;/summary&gt;
Public Class QueryPage
    Inherits Page

    ''' &lt;summary&gt;
    ''' Initializes a QueryPage.
    ''' &lt;/summary&gt;
    Public Sub New()
        InitializeComponent()
    End Sub

    ''' &lt;summary&gt;
    ''' Executes when the user navigates to this page.
    ''' &lt;/summary&gt;
    ''' &lt;param name="e"&gt;Event arguments.&lt;/param&gt;
    Protected Overrides Sub OnNavigatedTo(ByVal e As Windows.Navigation.NavigationEventArgs)
        x.Text = GetArgument("x")
        y.Text = GetArgument("y")
        z.Text = GetArgument("z")
    End Sub

    ''' &lt;summary&gt;
    ''' Gets a value passed in through the query if available.
    ''' &lt;/summary&gt;
    ''' &lt;param name="argName"&gt;The key to find.&lt;/param&gt;
    ''' &lt;returns&gt;The value associated with the key if available, otherwise "{Not Specified}".&lt;/returns&gt;
    Private Function GetArgument(ByVal argName As String) As String
        If NavigationContext.QueryString.ContainsKey(argName) Then
            Return NavigationContext.QueryString(argName)
        End If
        Return "{Not Specified}"
    End Function
End Class</sys:String>
    </src:SourceFile.Source>
  </src:SourceFile>
</src:SourceViewer>
    </StackPanel>
</UserControl>
